﻿using K.Client;
using System.Collections.Generic;
using System.Linq;

public class Item : KObj
{
    public long itemId;
    public int tplId;
    public long num;

    public Item()
    {
        Init();
    }

    public override void Init()
    {
        itemId = 0;
        tplId = 0;
        num = 0;
    }
}

public class ItemMgr : IBaseData
{
    public Dictionary<long, long> mItemPackage;
    public ItemMgr()
    {
        mItemPackage = new Dictionary<long, long>();
    }

    public void Init()
    {

    }

    public long GetNumByTplId(int tplId)
    {
        long count = 0;
        for (int idx = 0; idx < mItemPackage.Count; ++idx)
        {
            long objId = mItemPackage.ElementAt(idx).Value;
            Item item = ObjMgr.GetSingleton().GetObject(objId) as Item;
            if (item != null && item.tplId == tplId)
            {
                count += item.num;
            }
        }
        return count;
    }

    public Item GetItem(long uuid)
    {
        long objId = -1;
        if (mItemPackage.TryGetValue(uuid, out objId))
        {
            Item item = ObjMgr.GetSingleton().GetObject(objId) as Item;
            if (item != null) { return item; }
        }
        return null;
    }
}